<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/20/020
 * Time: 10:47
 */

namespace app\admin\controller;
use app\api\validate\CategoryValidate;

use app\api\model\Category as CategoryModel;


class Category extends Common {

    /**
     * 用户列表
     * @return \think\response\View
     */
    public function index() {
        $cates = CategoryModel::getCates();
        $this->assign('data', $cates);

        return view();
    }

    /**
     * 创建或者编辑品牌
     * @return \think\response\Json|\think\response\View
     */
    public function save_category() {
        $id = input('param.id', 0);
        if (request()->isAjax()) {
            $category_validate = new CategoryValidate();
            $category_validate->goCheck();
            $param = $category_validate->getDataByRule(input('param.'));
            $data = categoryModel::createOrUpdateCategory($param, $id);
            return json($data);
        } else {
            $data = [];
            if ($id > 0) {
                $data = CategoryModel::get($id);
            }
            $this->assign('data', $data);

            $cates = CategoryModel::getCates(0, 0, $id);
            $this->assign('cates', $cates);

            return view();
        }
    }
}